package com.example.demo.basic;

import org.apache.rocketmq.common.message.MessageConst;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName ScProducer
 * @Description
 * @Author zhangdachen
 * @Date 2021-09-15 13:39
 * @Version V1.0
 **/
@Component
public class ScProducer {
    @Resource
    private Source source;
    public void sendMessage(String msg){
        Map<String,Object> headers=new HashMap<>();
        headers.put(MessageConst.PROPERTY_TAGS,"testTag");
        MessageHeaders messageHeaders=new MessageHeaders(headers);
        Message<String> message= MessageBuilder.createMessage(msg,messageHeaders);
        this.source.output().send(message);
    }

}
